home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Magazine / C_Tutorial / Part-13 / PatchLib / source / PatchAlloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-26  |  2.0 KB  |  81 lines

  1. /*
  2. **    patch.library
  3. **
  4. **    Copyright © 1993-1997 by Stefan Fuchs
  5. **        Freely distributable.
  6. */
  7.  
  8. #ifndef _PATCH_INCLUDES_H
  9. #include "patch_includes.h"
  10. #endif
  11.  
  12.  
  13. /****** patch.library/PatchAlloc ***************************************
  14. *
  15. *   NAME
  16. *        PatchAlloc -- Allocate and initialize structures (V5)
  17. *
  18. *   SYNOPSIS
  19. *        structure = PatchAlloc(type)
  20. *                               D0
  21. *
  22. *        APTR PatchAlloc(ULONG type);
  23. *
  24. *   FUNCTION
  25. *        Allocate and initialize structures for use with patch.library.
  26. *
  27. *   NOTE
  28. *        Call PatchFreeVec() to free the memory unless documented otherwise.
  29. *
  30. *   INPUTS
  31. *        type = type of structure to allocate
  32. *
  33. *        Currently defined types:
  34. *        PS_TYPE_XRESULT - Allocate a PatchXResult structure used 
  35. *                          in conjunction with the Extended-Result-System
  36. *                          (See Example below)
  37. *
  38. *   RESULT
  39. *        structure = pointer to a structure or NULL on failure
  40. *
  41. *   EXAMPLE
  42. *        To add 30 ticks to the each dos.library/Delay() function
  43. *        your patchcode would look like this (in SAS/C):
  44. *
  45. *       __asm __saveds struct PatchXResult *MyDelay(register __d1 ULONG ticks)
  46. *       {
  47. *               struct PatchXResult *xresult;
  48. *               ticks += 30;
  49. *               xresult = (struct PatchXResult *)PatchAlloc(PS_TYPE_XRESULT);
  50. *               if(xresult )
  51. *               {
  52. *                        xresult->pxr_RegD1 = ticks;
  53. *                        xresult->pxr_RegPattern = PATREG_D1;
  54. *               }
  55. *               return(xresult);
  56. *       }
  57. *
  58. *
  59. *   SEE ALSO
  60. *        GetPatch(), PatchFreeVec(), patch.h
  61. *
  62. ******************************************************************************
  63. *
  64. */
  65.  
  66. APTR LIBFUNC PatchAlloc( REGD0 ULONG structtype GNUC_REGD0)
  67. {
  68. struct PatchXResult *patchxresult;
  69.     switch(structtype)
  70.     {
  71.         case PS_TYPE_XRESULT:
  72.               patchxresult = AAllocmem(sizeof(struct PatchXResult), MEMF_CLEAR| MEMF_PUBLIC, NULL);
  73.             if(patchxresult)
  74.             {
  75.                 patchxresult->pxr_Node.ln_Type = PS_TYPE_XRESULT;
  76.                 return(patchxresult);
  77.             }
  78.             break;
  79.     }
  80.     return(NULL);
  81. }